<%--
  Created by IntelliJ IDEA.
  User: BYL
  Date: 2022/6/29
  Time: 11:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript">
        //添加商品
        function addProduct() {
            window.location.href = "${pageContext.request.contextPath}/add.jsp";
        }
        //删除商品
        function p_del() {
            var msg = "您确定要删除该学生信息吗？";
            if (confirm(msg)==true){
                return true;
            }else{
                return false;
            }
        }

        window.onload=function(){
            // 给删除选中按钮添加单击事件
            document.getElementById("delSelected").onclick=function () {
                var flag = false;
                if(confirm("你确定要删除选中条目吗？")){
                    //判断是否有选中条目
                    var cbs = document.getElementsByName("uid");
                    for (var i = 0; i <cbs.length ; i++) {
                        if (cbs[i].checked) {
                            //有一个条目被选中
                            flag = true;
                            break;
                        }
                    }
                    if (flag) {//有条目被选中
                        //表单提交
                        document.getElementById("form").submit();
                    }
                }
            }
            //1、获取第一个cb
            document.getElementById("firstCb").onclick=function () {
                //2、获取下面列表所有的cb
                var cbs = document.getElementsByName("uid");
                //3、遍历
                for (var i = 0; i <cbs.length ; i++) {
                    //4、设置这些cbs[i]的checked的状态=firstCb的checked
                    cbs[i].checked = this.checked;
                }
            }
        }
    </script>
</head>
<body>
<form id="Form1" name="Form1"
      action="${pageContext.request.contextPath}/findUserByManyCondition"
      method="post">
    <table cellSpacing="1" cellPadding="0" width="100%" align="center" bgColor="#f5fafe" border="0">
        <TBODY>
        <tr>
            <td class="ta_01" align="center" bgColor="#afd1f3">
                <strong>查 询 条 件</strong>
            </td>
        </tr>
        <tr>
            <td>
                <table cellpadding="0" cellspacing="0" border="0" width="100%">
                    <tr>
                        <td height="22" align="center" bgColor="#f5fafe" class="ta_01">学生编号</td>
                        <td class="ta_01" bgColor="#ffffff">
                            <input type="text" name="id" size="15" value="" id="Form1_userName" class="bg" />
                        </td>
                        <td height="22" align="center" bgColor="#f5fafe" class="ta_01">地址：</td>
                        <td class="ta_01" bgColor="#ffffff">
                            <select name="address" class="form-control" id="address">
                                <option value="" selected="selected">--选择地址--</option>
                                <option value="广东">广东</option>
                                <option value="陕西">陕西</option>
                                <option value="北京">北京</option>
                                <option value="上海">上海</option>
                                <option value="天津">天津</option>
                                <option value="广西">广西</option>
                                <option value="河南">河南</option>
                                <option value="湖北">湖北</option>
                                <option value="河北">河北</option>
                                <option value="湖南">湖南</option>
                                <option value="四川">四川</option>
                                <option value="黑龙江">黑龙江</option>
                                <option value="吉林">吉林</option>
                                <option value="辽宁">辽宁</option>
                                <option value="山东">山东</option>
                                <option value="陕西">陕西</option>
                                <option value="山西">山西</option>
                                <option value="重庆">重庆</option>
                                <option value="贵州">贵州</option>
                                <option value="青海">青海</option>
                                <option value="云南">云南</option>
                                <option value="海南">海南</option>
                                <option value="甘肃">甘肃</option>
                                <option value="江西">江西</option>
                                <option value="江苏">江苏</option>
                                <option value="浙江">浙江</option>
                                <option value="安徽">安徽</option>
                                <option value="福建">福建</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td height="22" align="center" bgColor="#f5fafe" class="ta_01">学生名称：</td>
                        <td class="ta_01" bgColor="#ffffff">
                            <input type="text" name="name" size="15" value="" id="Form1_userName" class="bg" />
                        </td>
                        <td height="22" align="center" bgColor="#f5fafe" class="ta_01">账号：</td>
                        <td class="ta_01" bgColor="#ffffff">
                            <input type="text" name="username" size="15" value="" id="Form1_userName" class="bg" />
                        </td>

                    </tr>
                    <tr>
                        <td width="100" height="22" align="center" bgColor="#f5fafe" class="ta_01"></td>
                        <td class="ta_01" bgColor="#ffffff">
                            <font face="宋体" color="red"> &nbsp;</font>
                        </td>
                        <td align="right" bgColor="#ffffff" class="ta_01">
                            <br /><br />
                        </td>
                        <td align="right" bgColor="#ffffff" class="ta_01">
                            <button type="submit" id="search" name="search" value="&#26597;&#35810;" class="button_view">
                                &#26597;&#35810;
                            </button>
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="reset" name="reset" value="&#37325;&#32622;" class="button_view" />
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr><td align="left">${user.name}，欢迎您进入学生信息管理系统</td></tr>
        <tr>
            <td class="ta_01" align="center" bgColor="#6495ed"><strong>学 生 列 表</strong>
            </TD>
        </tr>
        <tr>

            <td class="ta_01" align="right">
                <button type="button" id="add" name="add" value="&#28155;&#21152;" class="button_add" onclick="addProduct()">
                    &#28155;&#21152;
                </button>
<%--                <button id="delSelected" type="button" onclick="delselect()">删除选中</button>--%>
                <a class="btn btn-primary" href="javascript:void(0);" id="delSelected">删除选中</a>
            </td>
        </tr>
        </TBODY>
    </table>
</form>
        <form id="form" action="${pageContext.request.contextPath}/delSelectedServlet" method="post">
        <tr>
            <td class="ta_01" align="center" bgColor="#f5fafe">
                <table cellspacing="0" cellpadding="1" rules="all"
                       bordercolor="gray" border="1" id="DataGrid1"
                       style="BORDER-RIGHT: gray 1px solid; BORDER-TOP: gray 1px solid; BORDER-LEFT: gray 1px solid; WIDTH: 100%; WORD-BREAK: break-all; BORDER-BOTTOM: gray 1px solid; BORDER-COLLAPSE: collapse; BACKGROUND-COLOR: #f5fafe; WORD-WRAP: break-word">
                    <tr style="FONT-WEIGHT: bold; FONT-SIZE: 12pt; HEIGHT: 20px; BACKGROUND-COLOR: #afd1f3">
                        <th align="center" width="2%"><input type="checkbox" id="firstCb"></th>
                        <td align="center" width="5%">学生编号</td>
                        <td align="center" width="5%">学生名称</td>
                        <td align="center" width="5%">性别</td>
                        <td align="center" width="5%">年龄</td>
                        <td align="center" width="5%">地址</td>
                        <td width="5%" align="center">QQ</td>
                        <td width="8%" align="center">邮箱</td>
                        <td width="5%" align="center">账号</td>
                        <td width="5%" align="center">密码</td>
                        <td width="5%" align="center">修改</td>
                        <td width="5%" align="center">删除</td>
                    </tr>
                    <!--  循环输出所有学生信息 -->
                    <c:forEach items="${ps}" var="p">
                        <tr onmouseover="this.style.backgroundColor = 'white'"
                            onmouseout="this.style.backgroundColor = '#F5FAFE';">
                            <td align="center" width="2%"><input type="checkbox" name="uid" value="${p.id}"></td>
                            <td style="CURSOR: hand; HEIGHT: 22px" align="center" width="4%">${p.id }</td>
                            <td style="CURSOR: hand; HEIGHT: 22px" align="center" width="6%">${p.name }</td>
                            <td style="CURSOR: hand; HEIGHT: 22px" align="center" width="4%">${p.gender }</td>
                            <td style="CURSOR: hand; HEIGHT: 22px" align="center" width="4%">${p.age }</td>
                            <td style="CURSOR: hand; HEIGHT: 22px" align="center" width="4%">${p.address }</td>
                            <td style="CURSOR: hand; HEIGHT: 22px" align="center" width="5%">${p.qq }</td>
                            <td style="CURSOR: hand; HEIGHT: 22px" align="center" width="8%">${p.email }</td>
                            <td style="CURSOR: hand; HEIGHT: 22px" align="center" width="6%">${p.username }</td>
                            <td style="CURSOR: hand; HEIGHT: 22px" align="center" width="6%">${p.passwd }</td>
                            <td align="center" style="HEIGHT: 22px" width="5%">
                                <a href="${pageContext.request.contextPath}/findUserServlet?id=${p.id}">修改</a>
                            </td>
                            <td align="center" style="HEIGHT: 22px" width="5%">
                                <a href="${pageContext.request.contextPath}/delUserServlet?id=${p.id}" onclick="javascript:return p_del()">删除</a>
                            </td>
                        </tr>
                    </c:forEach>
                </table>

            </td>
        </tr>
        </form>


</body>
</html>
